package com.java.yz.day11.ketang;

import java.util.ArrayList;
import java.util.Iterator;

//存储自定义对象并遍历
public class ArrayListDemo2 {
    public static void main(String[] args) {
        //创建一个存储对象
        ArrayList arrayList = new ArrayList();

        //创建存储数据
        Student s1 = new Student("张翰", 19);
        Student s2 = new Student("张勇", 20);
        Student s3 = new Student("张宇", 21);
        Student s4 = new Student("张翰", 19);

        arrayList.add(s1);
        arrayList.add(s2);
        arrayList.add(s3);
        arrayList.add(s4);

        System.out.println(arrayList);

        Iterator iterator = arrayList.iterator();
        while (iterator.hasNext()){
            Student s = (Student) iterator.next();
            System.out.println(s.getName()+"--"+s.getAge());
        }

        //怎么对元素进行去重呢？
    }
}
